package irnode;

import java.util.ArrayList;
import java.util.List;

import xyz.SimpleNode;

public class IRNode {
	protected String name;
	protected SimpleNode node;
	protected IRNode parent;
	protected List<IRNode> children;

	public IRNode(String name, SimpleNode node) {
		this.name = name;
		this.node = node;
		children = new ArrayList<IRNode>();
		parent = null;
	}

	public IRNode(String name, SimpleNode node, IRNode parent) {
		this.name = name;
		this.node = node;
		children = new ArrayList<IRNode>();
		this.parent = parent;
	}

	public IRNode getChild(int i) {
		return children.get(i);
	}

	public int getNumChildren() {
		return children.size();
	}

	public void addChild(IRNode n) {
		children.add(n);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public SimpleNode getNode() {
		return node;
	}

	public void setNode(SimpleNode node) {
		this.node = node;
	}

	public IRNode getParent() {
		return parent;
	}

	public void setParent(IRNode parent) {
		this.parent = parent;
	}

	public List<IRNode> getChildren() {
		return children;
	}

	public void setChildren(List<IRNode> children) {
		this.children = children;
	}

	public String toString() {
		return name;
	}

	public String toString(String prefix) {
		return prefix + toString();
	}

	/*
	 * Override this method if you want to customize how the node dumps out its
	 * children.
	 */

	public void dump(String prefix) {
		System.out.println(toString(prefix));
		if (children != null) {
			for (int i = 0; i < children.size(); ++i) {
				IRNode n = children.get(i);
				if (n != null) {
					n.dump(prefix + " ");
				}
			}
		}
	}
}
